import {
  createHeroSkillListService,
  uodateHeroSkillServeice,
  getHeroSkillListService,
} from "../service/skinList.service.js";
export const addSkins = async (ctx, next) => {
  const { skillList } = ctx.request.body;

  //判断当前是否有皮肤id
  const addList = skillList.filter((item) => !item.skinId);
  const updateList = skillList.filter((item) => item.skinId);

  try {
    await createHeroSkillListService(addList);
    for (const list of updateList) {
      await uodateHeroSkillServeice(list);
    }
    ctx.body = {
      code: 200,
      message: "操作成功",
      data: {},
    };
  } catch (err) {
    return ctx.app.emit(
      "error",
      {
        code: 10001,
        message: "创建失败",
        result: "",
      },
      ctx
    );
  }

  await next();
};
export const getSkinList = async (ctx, next) => {
  const { heroId } = ctx.request.query;
  try {
    const res = await getHeroSkillListService(heroId);
    ctx.body = {
      code: 200,
      message: "操作成功",
      data: res,
    };
  } catch (error) {
    return ctx.app.emit(
      "error",
      {
        code: 10001,
        message: "获取失败",
        result: "",
      },
      ctx
    );
  }
};
